class Solution(object):
    def maxProduct(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        def trans(word):
            mask = 0
            for c in word:
                bit = 1<<(ord(c)-ord('a'))
                mask = mask | bit
            return mask
        masks = [trans(word) for word in words]
        maxLen = 0
        for i in range(len(masks)):
            for j in range(i+1, len(masks)):
                if (masks[i]^masks[j]) & (masks[i]|masks[j]) == (masks[i]|masks[j]):
                    maxLen = max(maxLen, len(words[i])*len(words[j]))
        return maxLen

print(Solution().maxProduct(["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]))